<template>
  <div>单点登录跳转中...</div>
</template>
<script setup lang="tsx">
import { useRoute, useRouter } from 'vue-router';
import Storage from '@/framework/utils/Storage';
import { useUserStore } from '@/store/modules/user';
import { message } from 'ant-design-vue';
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const token = route.query.token;
const redirect = route.query.redirect_path;
if (token) {
  Storage.setCookie('token', token);
  userStore
    .afterLogin()
    .then((res) => {
      if (redirect) {
        router.replace({
          path: redirect + '',
        });
      } else {
        router.replace({
          name: 'home',
        });
      }
    })
    .catch((err) => {
      message.error('登录失败！');
      window.history.go(-1);
    });
} else {
  router.replace({
    name: 'Login',
  });
}
</script>
<style lang="less" scoped></style>
